<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/classes/smarty/plugins/function.filter.php, $Author:  $ */

function smarty_function_filter($params, &$smarty)
{
    $aData = $params['data'];
    unset($params['data']);
    if ( isset($params['any']) )
    {
    	$sAny = $params['any'];
    	unset($params['any']);
    }

    $aParams = array_merge($aData['params'], $params);
    $sOut = '';

    switch ($aData['type'])
    {
        case 'select':
            $sOut .= '<select';

            foreach ($aParams as $sParam => $sValue)
            {
                $sOut .= ' '.$sParam.'="'.$sValue.'"';
            }
            $sOut .= '>';

            if ( !empty($aData['select']['filter_selected_item']) && isset($params['default']) )
            {
            	// $aData['value'] = $aData['select']['filter_selected_item'];
            }

			if ( isset($sAny) )
			{
				$sOut .= '<option value="">'. App::format($sAny) .'</option>';
			}

            foreach ($aData['select'] as $sKey => $sValue)
            {
            	if ( $sKey != 'filter_selected_item' )
            	{
            		$sOut .= '<option value="'.$sKey.'"';
            		$sOut .= (strval($sKey) === strval($aData['value'])) ? ' selected="selected"' : '';
            		$sOut .= '>'. (isset($params['translate']) ? App::formatTranslate($sValue) : $sValue) .'</option>';
            	}
            }
            $sOut .= '</select>';
            break;
        case 'text':
            $sOut .= '<input type="text"';
            $aParams['value'] = $aData['value'];
            foreach ($aParams as $sParam => $sValue)
            {
                $sOut .= ' '.$sParam.'="'. htmlspecialchars($sValue) .'"';
            }
            $sOut .= ' />';
            break;
    }
    return $sOut;
}
?>